#!/bin/bash

# postinst script for driver-stmf
#
# see: dh_installdeb(1)

#set -e

# summary of how this script can be called:
#        * <postinst> \`configure' <most-recently-configured-version>
#        * <old-postinst> \`abort-upgrade' <new version>
#        * <conflictor's-postinst> \`abort-remove' \`in-favour' <package>
#          <new-version>
#        * <postinst> \`abort-remove'
#        * <deconfigured's-postinst> \`abort-deconfigure' \`in-favour'
#          <failed-install-package> <version> \`removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

PATH=/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

if [ "${BASEDIR:=/}" = "/" ]; then
    BASEDIR=""
else
    BASEDIR_OPT="-b $BASEDIR"
fi

case "$1" in
    configure)
        if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/kmdb/amd64/stmf ] && rm -f $BASEDIR/kernel/kmdb/amd64/stmf
	else
	    chmod 0555 "$BASEDIR/kernel/kmdb/amd64/stmf"
	    chown root:sys "$BASEDIR/kernel/kmdb/amd64/stmf"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/kmdb/amd64/stmf_sbd ] && rm -f $BASEDIR/kernel/kmdb/amd64/stmf_sbd
	else
	    chmod 0555 "$BASEDIR/kernel/kmdb/amd64/stmf_sbd"
	    chown root:sys "$BASEDIR/kernel/kmdb/amd64/stmf_sbd"
	fi
	chmod 0555 "$BASEDIR/usr/lib/mdb/kvm/amd64/stmf.so"
	chown root:sys "$BASEDIR/usr/lib/mdb/kvm/amd64/stmf.so"
	chmod 0555 "$BASEDIR/usr/lib/mdb/kvm/amd64/stmf_sbd.so"
	chown root:sys "$BASEDIR/usr/lib/mdb/kvm/amd64/stmf_sbd.so"
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/fct.conf ] && rm -f $BASEDIR/kernel/drv/fct.conf
	else
	    chmod 0644 "$BASEDIR/kernel/drv/fct.conf"
	    chown root:sys "$BASEDIR/kernel/drv/fct.conf"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/pppt.conf ] && rm -f $BASEDIR/kernel/drv/pppt.conf
	else
	    chmod 0644 "$BASEDIR/kernel/drv/pppt.conf"
	    chown root:sys "$BASEDIR/kernel/drv/pppt.conf"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/qlt.conf ] && rm -f $BASEDIR/kernel/drv/qlt.conf
	else
	    chmod 0644 "$BASEDIR/kernel/drv/qlt.conf"
	    chown root:sys "$BASEDIR/kernel/drv/qlt.conf"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/stmf.conf ] && rm -f $BASEDIR/kernel/drv/stmf.conf
	else
	    chmod 0644 "$BASEDIR/kernel/drv/stmf.conf"
	    chown root:sys "$BASEDIR/kernel/drv/stmf.conf"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/stmf_sbd.conf ] && rm -f $BASEDIR/kernel/drv/stmf_sbd.conf
	else
	    chmod 0644 "$BASEDIR/kernel/drv/stmf_sbd.conf"
	    chown root:sys "$BASEDIR/kernel/drv/stmf_sbd.conf"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/amd64/fct ] && rm -f $BASEDIR/kernel/drv/amd64/fct
	else
	    chmod 0755 "$BASEDIR/kernel/drv/amd64/fct"
	    chown root:sys "$BASEDIR/kernel/drv/amd64/fct"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/amd64/pppt ] && rm -f $BASEDIR/kernel/drv/amd64/pppt
	else
	    chmod 0755 "$BASEDIR/kernel/drv/amd64/pppt"
	    chown root:sys "$BASEDIR/kernel/drv/amd64/pppt"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/amd64/qlt ] && rm -f $BASEDIR/kernel/drv/amd64/qlt
	else
	    chmod 0755 "$BASEDIR/kernel/drv/amd64/qlt"
	    chown root:sys "$BASEDIR/kernel/drv/amd64/qlt"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/amd64/stmf ] && rm -f $BASEDIR/kernel/drv/amd64/stmf
	else
	    chmod 0755 "$BASEDIR/kernel/drv/amd64/stmf"
	    chown root:sys "$BASEDIR/kernel/drv/amd64/stmf"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/amd64/stmf_sbd ] && rm -f $BASEDIR/kernel/drv/amd64/stmf_sbd
	else
	    chmod 0755 "$BASEDIR/kernel/drv/amd64/stmf_sbd"
	    chown root:sys "$BASEDIR/kernel/drv/amd64/stmf_sbd"
	fi
	[ "$ZONEINST" = "1" ] || (grep -c "^fct " $BASEDIR/etc/name_to_major >/dev/null || ( add_drv -n  $BASEDIR_OPT  -m '* 0666 root sys' fct ) )
	[ "$ZONEINST" = "1" ] || (grep -c "^pppt " $BASEDIR/etc/name_to_major >/dev/null || ( add_drv -n  $BASEDIR_OPT  -m '* 0666 root sys' pppt ) )
	[ "$ZONEINST" = "1" ] || (grep -c "^qlt " $BASEDIR/etc/name_to_major >/dev/null || ( add_drv -n  $BASEDIR_OPT  -m '* 0666 root sys' qlt ) )
	[ "$ZONEINST" = "1" ] || (grep -c "^stmf " $BASEDIR/etc/name_to_major >/dev/null || ( add_drv -n  $BASEDIR_OPT  -m '* 0666 root sys' stmf ) )
	[ "$ZONEINST" = "1" ] || (grep -c "^stmf_sbd " $BASEDIR/etc/name_to_major >/dev/null || ( add_drv -n  $BASEDIR_OPT  -m '* 0666 root sys' stmf_sbd ) )
	
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument '$1'" >&2
        exit 1
    ;;
esac



# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

